<?php
/**
 * Zend_Service_Netflix_QueueItem Class
 *
 * @author Armando Padilla, armando_padilla_81@yahoo.com
 * @package Zend_Service_Netflix
 * 
 */ 
require_once "Utils.php";
 
class Zend_Service_Netflix_QueueItem { 
	
	/**
	 * Queue Item Id
	 * 
	 * @var String $id
	 */
	public $id;
	
	/**
	 * Position in the Queue.
	 *
	 * @var unknown_type
	 */
	public $position;
	
	/**
	 * Type of queue.  
	 * awaiting_release, available_now, saved
	 *
	 * @var unknown_type
	 */
	public $queueType; 
	
	
	/**
	 * Last updated date.
	 *
	 * @var unknown_type
	 */
	public $updated;
	
	/**
	 * Title.
	 *
	 * @var String.
	 */
	public $title;
	
	/**
	 * Id of the title.
	 *
	 * @var String.
	 */
	public $titleID;
	
	/**
	 * Title URL Id.  
	 *
	 * @var String.
	 */
	public $titleIDAsURL;
	
	
	
	public function __construct(){}
	
	/**
	 * Loads the data for the object
	 *
	 * @param SimpleXMLElement $simpleXMLObject
	 */
	public function loadXML(SimpleXMLElement $queueItemXml){
		
		//Set all property values.
		$this->position 	 = (string)$queueItemXml->position;
		$this->updated  	 = (string)$queueItemXml->updated;
		$this->id			 = (string)$queueItemXml->id;
		$this->title    	 = (string)$queueItemXml->title['regular'];
		
		$xml = simplexml_load_string($queueItemXml->asXML());
		
		//Get the title id.
		$titleIdInfo = $xml->xpath("link[@rel='http://schemas.netflix.com/catalog/title']");
		foreach($titleIdInfo as $info){
			$this->titleIDAsURL = (string)$info['href'];
			$this->titleId 		= Zend_Service_Netflix_Utils::parseTitleId((string)$info['href']);
		}
	
		
		//Get queue info
		$queueInfo = $xml->xpath("category[@scheme='http://api.netflix.com/categories/queue_availability']");
		foreach($queueInfo as $info){
			$this->queueType = (string)$info['label'];
		}
			
	}
	
}
?>